package com.hangwei.paperless.utils;

import android.view.View;

/**
 * Created by 张龙臣 on 2018/12/11.
 */

public abstract class NotFastClickListener implements View.OnClickListener {
    private long lastClickTime;
    private int mLastId;

    /**
     * 防止button快速连点
     *
     * @param v
     * @return
     */
    private boolean checkClick(View v) {
        if (mLastId != v.getId()) {
            mLastId = v.getId();
            return true;
        }
        boolean flag = false;
        long currentClickTime = System.currentTimeMillis();
        if ((currentClickTime - lastClickTime) >= 500) {
            mLastId = v.getId();
            flag = true;
        }
        lastClickTime = currentClickTime;
        return flag;
    }

    @Override
    public void onClick(View v) {
        if (checkClick(v)) {
            //处理点击事件
            isNotFastClick(v);
        } else doubleClick(v);
    }

    protected void doubleClick(View v) {
//        ToastUtil.showCenterToast("请勿重复点击");
    }

    protected void isNotFastClick(View v) {
    }
}
